package ar.com.ford.it.fullEconomics.view.form;

import java.util.Collection;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.ValidatorForm;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesf01Fulleconom;
import ar.com.ford.it.fullEconomics.struct.FullEconomicsExcercisesStruct;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;

public class FullEconomicsPopupForm extends ValidatorForm {
    private String section;
    private String supplierTypeSel;
    private String supplierCode;
    private String statusSel;
    private String commoditySel;
    private String showLastApprovedOnly;
    private String partClassSel;
    private String partPrefix;
    private String partBase;
    private String partSufix;
    private String dateTypeSel;
    private String dateMin;
    private String dateMax;
    private String userActionTypeSel;
    private String userId;
    private String vehicleLineSel;
    private String econLevel1MinDate;
    private String econLevel1MaxDate;
    private String econLevel2MinDate;
    private String econLevel2MaxDate;
    private Collection<Teesf01Fulleconom> fullEconomics;
    private Teesf01Fulleconom teesf01FulleconomSelected;
    private String fullEconomicCodeid;

    public void resetForm() {
        this.section = null;
        this.supplierTypeSel = null;
        this.supplierCode = null;
        this.statusSel = null;
        this.commoditySel = null;
        this.showLastApprovedOnly = null;
        this.partClassSel = null;
        this.partPrefix = null;
        this.partBase = null;
        this.partSufix = null;
        this.dateTypeSel = null;
        this.dateMin = null;
        this.dateMax = null;
        this.userActionTypeSel = null;
        this.userId = null;
        this.vehicleLineSel = null;
        this.econLevel1MinDate = null;
        this.econLevel1MaxDate = null;
        this.econLevel2MinDate = null;
        this.econLevel2MaxDate = null;
        this.fullEconomics = null;
        this.teesf01FulleconomSelected = null;
        this.fullEconomicCodeid = null;
    }

    public FullEconomicsExcercisesStruct getFindParameters(
                                                           FullEconomicsWslxUser user) {

        FullEconomicsExcercisesStruct parameters = new FullEconomicsExcercisesStruct();

        parameters.setCommoditySel(this.getCommoditySel());
        parameters.setDateTypeSel(this.getDateTypeSel());
        parameters.setEconLevel1MaxDate(this.getEconLevel1MaxDate());
        parameters.setEconLevel1MinDate(this.getEconLevel1MinDate());
        parameters.setEconLevel2MaxDate(this.getEconLevel2MaxDate());
        parameters.setEconLevel2MinDate(this.getEconLevel2MinDate());
        parameters.setShowLastApprovedOnly(this.getShowLastApprovedOnly());
        parameters.setStatusSel(this.getStatusSel());
        parameters.setSupplierTypeSel(this.getSupplierTypeSel());
        parameters.setUserActionTypeSel(this.getUserActionTypeSel());
        parameters.setVehicleLineSel(this.getVehicleLineSel());
        parameters.setPlant(user.getTeesg01Plant());
        parameters.setSupplierCode(this.getSupplierCode());
        parameters.setPartClassSel(this.getPartClassSel());
        parameters.setPartPrefix(this.getPartPrefix());
        parameters.setPartBase(this.getPartBase());
        parameters.setPartSufix(this.getPartSufix());
        parameters.setDateMin(this.getDateMin());
        parameters.setDateMax(this.getDateMax());
        parameters.setUserId(this.getUserId());

        return parameters;
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        this.section = section;
    }

    public String getCommoditySel() {
        return commoditySel;
    }

    public void setCommoditySel(String commoditySel) {
        this.commoditySel = commoditySel;
    }

    public String getDateMax() {
        return dateMax;
    }

    public void setDateMax(String dateMax) {
        this.dateMax = dateMax;
    }

    public String getDateMin() {
        return dateMin;
    }

    public void setDateMin(String dateMin) {
        this.dateMin = dateMin;
    }

    public String getDateTypeSel() {
        return dateTypeSel;
    }

    public void setDateTypeSel(String dateTypeSel) {
        this.dateTypeSel = dateTypeSel;
    }

    public String getEconLevel1MaxDate() {
        return econLevel1MaxDate;
    }

    public void setEconLevel1MaxDate(String econLevel1MaxDate) {
        this.econLevel1MaxDate = econLevel1MaxDate;
    }

    public String getEconLevel1MinDate() {
        return econLevel1MinDate;
    }

    public void setEconLevel1MinDate(String econLevel1MinDate) {
        this.econLevel1MinDate = econLevel1MinDate;
    }

    public String getEconLevel2MaxDate() {
        return econLevel2MaxDate;
    }

    public void setEconLevel2MaxDate(String econLevel2MaxDate) {
        this.econLevel2MaxDate = econLevel2MaxDate;
    }

    public String getEconLevel2MinDate() {
        return econLevel2MinDate;
    }

    public void setEconLevel2MinDate(String econLevel2MinDate) {
        this.econLevel2MinDate = econLevel2MinDate;
    }

    public Collection<Teesf01Fulleconom> getFullEconomics() {
        return fullEconomics;
    }

    public void setFullEconomics(Collection<Teesf01Fulleconom> fullEconomics) {
        this.fullEconomics = fullEconomics;
    }

    public String getPartBase() {
        return partBase;
    }

    public void setPartBase(String partBase) {
        this.partBase = partBase;
    }

    public String getPartClassSel() {
        return partClassSel;
    }

    public void setPartClassSel(String partClassSel) {
        this.partClassSel = partClassSel;
    }

    public String getPartPrefix() {
        return partPrefix;
    }

    public void setPartPrefix(String partPrefix) {
        this.partPrefix = partPrefix;
    }

    public String getPartSufix() {
        return partSufix;
    }

    public void setPartSufix(String partSufix) {
        this.partSufix = partSufix;
    }

    public String getShowLastApprovedOnly() {
        return showLastApprovedOnly;
    }

    public void setShowLastApprovedOnly(String showLastApprovedOnly) {
        this.showLastApprovedOnly = showLastApprovedOnly;
    }

    public String getStatusSel() {
        return statusSel;
    }

    public void setStatusSel(String statusSel) {
        this.statusSel = statusSel;
    }

    public String getSupplierCode() {
        return supplierCode;
    }

    public void setSupplierCode(String supplierCode) {
        this.supplierCode = supplierCode;
    }

    public String getSupplierTypeSel() {
        return supplierTypeSel;
    }

    public void setSupplierTypeSel(String supplierTypeSel) {
        this.supplierTypeSel = supplierTypeSel;
    }

    public String getUserActionTypeSel() {
        return userActionTypeSel;
    }

    public void setUserActionTypeSel(String userActionTypeSel) {
        this.userActionTypeSel = userActionTypeSel;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getVehicleLineSel() {
        return vehicleLineSel;
    }

    public void setVehicleLineSel(String vehicleLineSel) {
        this.vehicleLineSel = vehicleLineSel;
    }

    /**
     * Setea el fullEE seleccionado
     * 
     * @param key
     * @param value
     */
    public void setFullEEMapped(String key, String value) {
        List fullEEValues = (List) this.getFullEconomics();
        if (fullEEValues != null)
            this.setTeesf01FulleconomSelected((Teesf01Fulleconom) fullEEValues
                    .get(Integer.parseInt(key) - 1));
    }

    public Teesf01Fulleconom getTeesf01FulleconomSelected() {
        return teesf01FulleconomSelected;
    }

    public void setTeesf01FulleconomSelected(
                                             Teesf01Fulleconom teesf01FulleconomSelected) {
        this.teesf01FulleconomSelected = teesf01FulleconomSelected;
    }

    /**
     * Genera las validaciones necesarias.
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors ae = new ActionErrors();

        // Si se selecciono solo ver los ultimos aprovados
        if (this.showLastApprovedOnly != null
                && this.showLastApprovedOnly.equals("true")) {
            if (!this.statusSel.equals("-1")
                    && !this.statusSel.equals("Approved")) {
                ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                        "fullEconomics.error.estados.diferentes"));
            }
        }
        return ae;
    }

    public String getFullEconomicCodeid() {
        return fullEconomicCodeid;
    }

    public void setFullEconomicCodeid(String fullEconomicCodeid) {
        this.fullEconomicCodeid = fullEconomicCodeid;
    }

}

